<template>
  <div style="margin-bottom: 20px;">
    <el-dialog :title="edit_main_title2" append-to-body v-dialogDrag :visible.sync="edit_flag2"
               @open="handleOpenConfig" :before-close="createHandleClose" width="500px">
      <el-form class="ml30" ref="sendMsgRef" :rules="rules" :model="createObj">
        <el-form-item label='库存类型:' prop="handlerType">
          <el-select v-model="createObj.handlerType" class="w184" clearable filterable remote reserve-keyword placeholder="请选择状态">
            <el-option key="1" label="移实顺" value="20"></el-option>
            <el-option key="2" label="提车指令出库" value="30"></el-option>
            <el-option key="3" label="返工厂" value="40"></el-option>
            <el-option key="4" label="交舒憨头" value="60"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label='备注：' prop="remarks">
          <el-input type="textarea"  :rows="3" v-model="createObj.remarks"
                    placeholder="非必填" style="width: 300px"></el-input>
        </el-form-item>
      </el-form>
      <el-row type="flex" justify="end">
        <el-button type="primary" @click="createHandleClose">取消</el-button>
        <el-button type="primary" :disabled="createConfirmBtnFlag" @click="createConfirmClick">确定</el-button>
      </el-row>
      <div style="height:20px"></div>
    </el-dialog>
  </div>
</template>

<script type="text/javascript">
  import * as FactoryPreparationAPI from '@/api/factoryPreparation/factoryPreparation'
  export default {
    name: '',
    components: {
    },
    props: ['edit_flag2', 'edit_main_title2', 'edit_select_row', 'edit_params'],
    data() {
      return {
        title_data: {},
        table_data: [],
        createConfirmBtnFlag: false, // 按钮
        storeAreaData: [], // 仓库-库区
        createObj: {
          handlerType: '30',
          remarks: ''
        },
        multipleSelection: [],
        rules: {
          handlerType: [
            { required: true, message: '请选择库存类型', trigger: 'change' }
          ]
        }
      }
    },
    methods: {
      // 弹窗页打开初始
      handleOpenConfig(data) {
        this.createConfirmBtnFlag = false
        this.multipleSelection = this.$props.edit_select_row
        this.createObj = {
          handlerType: '30',
          remarks: ''
        }
        // console.log('this.$props.edit_select_row', this.$props.edit_select_row)
      },
      // 出库提交
      createConfirmClick() {
        const that = this
        that.$refs['sendMsgRef'].validate(valid => {
          if (valid) {
            this.createConfirmBtnFlag = true
            const vinsIds = []
            const pIds = []
            this.multipleSelection.map(item => {
              vinsIds.push(item.vin)
              pIds.push(item.id)
            })
            const toParams = {
              prepareInboundId: pIds.length > 1 ? pIds.join(',') : pIds[0],
              vins: vinsIds.length > 1 ? vinsIds.join(',') : vinsIds[0],
              handlerType: that.createObj.handlerType,
              remarks: that.createObj.remarks
            }
            FactoryPreparationAPI.factoryStockOutboundPrepare(toParams).then(result => {
              if (result.code === 0) {
                this.$message({
                  message: '备料出库成功',
                  type: 'success',
                  duration: 2000
                })
                this.createConfirmBtnFlag = false
                this.$emit('edit-confirm', false)
              } else {
                this.$message({
                  title: '错误提示',
                  message: result.message,
                  type: 'error',
                  duration: 2000
                })
                this.createConfirmBtnFlag = false
              }
            }).catch(() => {
              this.createConfirmBtnFlag = false
            })
          }
        })
      },
      createHandleClose() {
        this.$emit('edit-close', false)
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
